import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";

/**
 * TenantManager.js - 租户管理员 model
 * @date: 2019-01-10
 */
import { getResponse, createPagination } from 'utils/utils';
import { queryMapIdpValue } from 'services/api';
import { clearLogs as _clearLogs, fetchMembers as _fetchMembers } from "../services/tenantManagerService";
export default {
  namespace: 'tenantManager',
  state: {
    list: [],
    pagination: [],
    typeList: [],
    // 审计类型
    clearTypeList: [] // 清除类型

  },
  effects: {
    // 获取初始化数据
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(_ref, _ref2) {
      var payload, call, put, lovCodes, res, typeList, clearTypeList;
      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              lovCodes = payload.lovCodes;
              _context.t0 = getResponse;
              _context.next = 6;
              return call(queryMapIdpValue, _objectSpread(_objectSpread({}, lovCodes), {}, {
                clearTypeList: 'CPFM.AUDIT_LOG.CLEAR_TYPE'
              }));

            case 6:
              _context.t1 = _context.sent;
              res = (0, _context.t0)(_context.t1);
              typeList = res.typeList, clearTypeList = res.clearTypeList;
              _context.next = 11;
              return put({
                type: 'updateState',
                payload: {
                  typeList: typeList,
                  clearTypeList: clearTypeList
                }
              });

            case 11:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    // 清除日志
    clearLogs: /*#__PURE__*/_regeneratorRuntime.mark(function clearLogs(_ref3, _ref4) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function clearLogs$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call;
              _context2.next = 4;
              return call(_clearLogs, payload);

            case 4:
              result = _context2.sent;
              return _context2.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context2.stop();
          }
        }
      }, clearLogs);
    }),
    // 获取登录记录
    fetchMembers: /*#__PURE__*/_regeneratorRuntime.mark(function fetchMembers(_ref5, _ref6) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchMembers$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call, put = _ref6.put;
              _context3.next = 4;
              return call(_fetchMembers, payload);

            case 4:
              result = _context3.sent;
              result = getResponse(result);

              if (!result) {
                _context3.next = 9;
                break;
              }

              _context3.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  list: result.content,
                  pagination: createPagination(result)
                }
              });

            case 9:
            case "end":
              return _context3.stop();
          }
        }
      }, fetchMembers);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref7) {
      var payload = _ref7.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};